package com.shop.cereshop.app.dl.logic.controller;

import com.shop.cereshop.app.dl.logic.service.CereShopCommissionRecordService;
import com.shop.cereshop.app.dl.logic.utils.ResultInfo;
import com.shop.cereshop.app.service.buyer.CereBuyerUserService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.utils.EmptyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 况鑫威
 * @Date: 2021/7/20
 * @Time: 11:35
 * @ClassName: CereShopCommissionRecordController
 * @Description: com.shop.cereshop.app.dl.logic.controller
 */
@RestController
@RequestMapping("/commissionRecord")
public class CereShopCommissionRecordController {

    @Autowired
    private CereShopCommissionRecordService cereShopCouponRecordingsService;

    @Autowired
    private CereBuyerUserService cereBuyerUserService;

    /**
     * 功能描述: 获取佣金记录
     * @Param:
     * @return:
     * @Author: 况鑫威
     * @Date: 2021/7/20
     * @Time: 11:35
     */
    @PostMapping("/getCommissionRecords")
    public ResultInfo<?> getCommissionRecords(HttpServletRequest request, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                              @RequestParam(value = "row", defaultValue = "10") Integer row) throws CoBusinessException{
        String token = request.getHeader("Authorization");
        CereBuyerUser user = null;
        if (!EmptyUtils.isEmpty(token)) {
            //根据token查询用户信息
            user = cereBuyerUserService.findByToken(token);
        }
        if(user == null){
            throw new CoBusinessException(CoReturnFormat.USER_NOT_LOGIN);
        }
        return new ResultInfo(cereShopCouponRecordingsService.getCommissionRecords(user, page, row));
    }

}
